package Teacher;

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;

import javax.swing.*;

import CommonPanel.*;
import Database.*;
import Exception.*;
import General.*;
import GenericMethod.*;
import Manager.*;
import Projo.*;
import Teacher.Assessment.*;
import Teacher.Course.*;
import Teacher.Examination.*;
import Teacher.Help.*;
import Teacher.Penalty.*;

public class WindowTeacher extends JFrame
{
	//Variable Declaration
	private CallDB callDB;
	private Connection connection;
	private SetDimension setDimension;
	
	private Container container;
	private JMenuBar menuBar;
	
	private JMenu menuHome, menuReport, menuManagement, menuAbout;
	
	private JMenuItem itemSwitch, itemExit, itemAssessement, itemExamination, itemCourse, itemPenalty, itemLaunch, itemFAQ, itemHelp, itemContact;
	private JPanel currentPanel;
	
	private HeaderPanel headerPanel;
	private MainPanel mainPanel;
	
	private PanelAssessment panelAssessment;
	
	private PanelExamination panelExamination;
	private PanelCreateModExamination panelCreateModExamination;

	private PanelCourse panelCourse;
	private PanelCreateModCourse panelCreateModCourse;
		
	private PanelPenalty panelPenalty;
	private PanelCreateModPenalty panelCreateModPenalty;
	
	private PanelAbout panelAbout;
	private PanelLaunchExamination panelLaunchExamination;
	
	private ArrayList<Student> arrayStudent = new ArrayList<Student>();
	private Student student;
	private ProjoScreen projoScreen;
	
	private String titleLabel;
	private int cptTab;
	
	private boolean panelAssessmentFlag = false, panelExaminationFlag = false, panelCourseFlag = false, panelPenaltyFlag = false, panelLaunchExaminationFlag = false;
	private boolean panelCreateModExaminationFlag = false, panelCreateModPenaltyFlag = false, panelCreateModCourseFlag = false;
	
	private String pathElsa = "//localhost:3306/elsa", user = "root", password = "";
	
	MyActionListener actionListener;
	
	public WindowTeacher() throws LoadDriverException, CheckDataException, OpenConnectionException
	{
		//Setting window
		super("Teacher");
		
		setDimension = new SetDimension();
		setDimension.setBoundFrame(this, 800, 800);
		
		callDB = new CallDB(); //Initialize a CallDB object
		connection = callDB.openConnection(pathElsa, user, password);//Open a connection
		
		//Listener
		MyWindowListener windowListener = new MyWindowListener(); //Listener of the window
		this.addWindowListener(windowListener); //Link the window listener
		
		actionListener = new MyActionListener(); //Listener for the different panel
				
		addMenuBar(actionListener); //Link the listener for menubar
		addItemMenuListener(actionListener); //Link the listener for item
		setSwitchZone();
		
		//Set the container
	    container = getContentPane();
		container.setLayout(new BorderLayout());
	    
		headerPanel = new HeaderPanel(); //Create the headerPanel
		
		showPanelMain(actionListener); //Pass through the showPanelMain method to show the mainPanel
		
		currentPanel = new JPanel(); //Create the currentPanel
		currentPanel = mainPanel; //Set the current panel as mainPanel
		
		//Show the container
		container.add(headerPanel, BorderLayout.NORTH);
		container.add(mainPanel, BorderLayout.CENTER);

		setResizable(false); //Not allow to resize
		setVisible(true); //Render visible
	}
	
	public void showPanelMain(MyActionListener actionListener) throws LoadDriverException, CheckDataException //To show Main Panel
	{
		mainPanel = new MainPanel(callDB, connection); //Create the panel
		mainPanel.setName("mainPanel"); //Set the name
	}
	
	public void showPanelAssessment() throws CheckDataException, FormatScrollPaneException, LoadDriverException
	{
		setCurrentPanelFlags(false); //Change the current panel flag to false
		
		String[] tabHeader = {"Name", "Date"};
		GeneralMethod.clearAndSetHeader(tabHeader, "left");
		
		GeneralInformation.createExamModel(connection);
		GeneralMethod.setLeftModel(GeneralInformation.getExamModel()); //Set the Generic Left JTable by the MyTableModel
		
		String[] tabHeaderDescript = {"Matricule", "Firstname", "Lastname"};
		GeneralMethod.clearAndSetHeader(tabHeaderDescript, "descript");
					
		panelAssessment = new PanelAssessment(callDB, connection); //Create a new Assessment panel
		panelAssessment.setName("panelAssessment"); //Set the name of the panel

		addNewAndRemoveOldPanel(panelAssessment); //Change the current panel
		
		setCurrentPanelFlags(true); //Change the current panel flag to true
	}
	
	public void showPanelExamination() throws CheckDataException, OperationImpossibleException, FormatScrollPaneException, LoadDriverException
	{
		setCurrentPanelFlags(false); //Change the current panel flag to false
		
		String[] tabHeader = {"Name", "Date"}; //Create the headers of the columns
		GeneralMethod.clearAndSetHeader(tabHeader, "left"); //Fill the arrayList by the tabHeader
		
		GeneralInformation.createExamModel(connection);
		GeneralMethod.setLeftModel(GeneralInformation.getExamModel()); //Set the Generic Left JTable by the MyTableModel
		
		GeneralInformation.createCourseFullModel(connection); //To avoid Null Pointer Exception cause of different test
		
		if(GeneralInformation.getCourseLeftModel().getRowCount() == 0) //If there is no course available
			throw new OperationImpossibleException(); //Show an error
		
		panelExamination = new PanelExamination(callDB, connection); //Create a new Assessment panel
		panelExamination.setName("panelExamination"); //Set the name of the panel
		
		//Add Listeners
		MyActionListener actionListener = new MyActionListener();
		panelExamination.getButtonCreate().addActionListener(actionListener);
		panelExamination.getButtonModify().addActionListener(actionListener);
		
		addNewAndRemoveOldPanel(panelExamination); //Change the current panel
		
		setCurrentPanelFlags(true); //Change the current panel flag to true
	}
	
	public void showPanelCourse() throws CheckDataException, FormatScrollPaneException, LoadDriverException
	{
		setCurrentPanelFlags(false); //Change the current panel flag to false
		
		String[] tabHeader = {"Lastname", "Course"}; //Create the headers of the columns
		GeneralMethod.clearAndSetHeader(tabHeader, "left"); //Fill the arrayList by the tabHeader

		GeneralInformation.createCourseLeftModel(connection); //Initialize the Generic Model
		GeneralMethod.setLeftModel(GeneralInformation.getCourseLeftModel()); //Set the Generic Left JTable by the MyTableModel
		
		String[] tabHeaderDescript = {"Firstname", "Lastname"};
		GeneralMethod.clearAndSetHeader(tabHeaderDescript, "descript");
		
		panelCourse = new PanelCourse(callDB, connection); //Create a new Course panel
		panelCourse.setName("panelCourse"); //Set the name of the panel
		
		//Add Listener
		MyActionListener actionListener = new MyActionListener();
		panelCourse.getButtonCreate().addActionListener(actionListener);
		panelCourse.getButtonModify().addActionListener(actionListener);
		
		addNewAndRemoveOldPanel(panelCourse); //Change the current panel
					
		setCurrentPanelFlags(true); //Change the current panel flag to true
	}
	
	public void showPanelPenalty() throws CheckDataException, FormatScrollPaneException, LoadDriverException //Show the Penalty panel
	{
		setCurrentPanelFlags(false); //Change the current panel flag to false
		
		String[] tabHeader = {"Name", "Date"}; //Create the headers of the columns
		GeneralMethod.clearAndSetHeader(tabHeader, "left"); //Fill the arrayList by the tabHeader
		
		GeneralInformation.createPenaltyModel(connection);
		GeneralMethod.setLeftModel(GeneralInformation.getPenaltyModel()); //Set the Generic Left JTable by the MyTableModel
		
		String[] tabDescriptHeader = {"Time", "Percentage"};
		GeneralMethod.clearAndSetHeader(tabDescriptHeader, "descript");
		
		panelPenalty = new PanelPenalty(callDB, connection); //Create a new Penalty panel
		panelPenalty.setName("panelPenalty"); //Set the name of the panel

		//Add Listeners
		MyActionListener actionListener = new MyActionListener();
		panelPenalty.getButtonCreate().addActionListener(actionListener);
		panelPenalty.getButtonModify().addActionListener(actionListener);
		
		addNewAndRemoveOldPanel(panelPenalty); //Change the current panel
		
		setCurrentPanelFlags(true); //Change the current panel flag to true
	}
	
	public void showCreateModExamination(String buttonTitle) throws ComboModelException, CheckDataException, FormatScrollPaneException, LoadDriverException
	{
		setCurrentPanelFlags(false); //Change the current panel flag to false
			
		String[] tabHeader = {"Matricul", "Firstname", "Lastname"}; //Create the headers of the columns
		GeneralMethod.clearAndSetHeader(tabHeader, "right"); //Fill the arrayList by the tabHeader

		GeneralInformation.createStudentModel(connection);
		GeneralMethod.setRightModel(GeneralInformation.getStudentModel()); //Set the Generic Left JTable by the MyTableModel
		
		if(buttonTitle.toString().equals("Create"))
			panelCreateModExamination = new PanelCreateModExamination(callDB, connection); //Create a new CreateMod panel
		else if(buttonTitle.toString().equals("Modify"))
		{
			int selectedRow = panelExamination.getTableLeft().convertRowIndexToModel(panelExamination.getTableLeft().getSelectedRow()); //Get the index of the selected row
			int idExam = Integer.parseInt(GeneralInformation.getExamModel().getValueAt(selectedRow, 2).toString()); //Get the id of the examination.id field in the model
			GeneralInformation.setIdSelectedLeftTable(idExam); //Set the good value
			String fieldName = (String)GeneralInformation.getExamModel().getValueAt(selectedRow, 0);
			panelCreateModExamination = new PanelCreateModExamination(callDB, connection, fieldName); //Create a new CreateMod panel
		}
		//else{} //for the other case to prevent evolution
		
		panelCreateModExamination.getButtonBack().addActionListener(actionListener);
		
		panelCreateModExamination.setName("panelCreateModExamination"); //Set the name of the panel
					
		addNewAndRemoveOldPanel(panelCreateModExamination); //Change the current panel
		
		setCurrentPanelFlags(true); //Change the current panel flag to true
	}
	
	public void showCreateModCourse(String buttonTitle) throws CheckDataException, FormatScrollPaneException, LoadDriverException
	{
		setCurrentPanelFlags(false); //Change the current panel flag to false
					
		String[] tabHeader = {"Year", "Section", "Group"}; //Create the headers of the columns
		GeneralMethod.clearAndSetHeader(tabHeader, "right"); //Fill the arrayList by the tabHeader

		GeneralInformation.initClassRightModel(connection);
		GeneralMethod.setRightModel(GeneralInformation.getClassRightModel()); //Set right model
		
		String[] tabAccountHeader = {"Firstname", "Lastname"};
		GeneralMethod.clearAndSetHeader(tabAccountHeader, "account");
		
		GeneralInformation.initAccountModel(connection);
		
		if(buttonTitle.toString().equals("Create"))
			panelCreateModCourse = new PanelCreateModCourse(callDB, connection); //Create a new CreateMod panel
		else if(buttonTitle.toString().equals("Modify"))
		{
			int selectedRow = panelCourse.getTableLeft().convertRowIndexToModel(panelCourse.getTableLeft().getSelectedRow()); //Get the index of the selected row
			int courseId = Integer.parseInt(GeneralMethod.getLeftModel().getValueAt(selectedRow, 3).toString());
			GeneralInformation.setIdSelectedLeftTable(courseId); //Set the good value
			String fieldName = (String)GeneralMethod.getLeftModel().getValueAt(selectedRow, 1);
			panelCreateModCourse = new PanelCreateModCourse(callDB, connection, fieldName); //Create a new CreateMod panel				
		}
		
		panelCreateModCourse.getButtonBack().addActionListener(actionListener);

		panelCreateModCourse.setName("panelCreateModCourse"); //Set the name of the panel
		
		addNewAndRemoveOldPanel(panelCreateModCourse); //Change the current panel
		
		setCurrentPanelFlags(true); //Change the current panel flag to true
	}
	
	public void showCreateModPenalty(String buttonTitle) throws CheckDataException, FormatScrollPaneException, LoadDriverException, InsertionDataException
	{
		setCurrentPanelFlags(false); //Change the current panel flag to false
		
		String[] tabHeader = {"Time", "Percentage"}; //Create the headers of the columns
		GeneralMethod.clearAndSetHeader(tabHeader, "right"); //Fill the arrayList by the tabHeader
		
		if(buttonTitle.toString().equals("Create"))
			panelCreateModPenalty = new PanelCreateModPenalty(callDB, connection); //Create a new CreateMod panel
		else if(buttonTitle.toString().equals("Modify"))
		{
			int selectedRow = panelPenalty.getTableLeft().convertRowIndexToModel(panelPenalty.getTableLeft().getSelectedRow()); //Get the index of the selected row
			int idPenaltyModel = Integer.parseInt(GeneralMethod.getLeftModel().getValueAt(selectedRow, 2).toString());
			GeneralInformation.setIdSelectedLeftTable(idPenaltyModel); //Set the good value
			String fieldName = (String)GeneralMethod.getLeftModel().getValueAt(selectedRow, 0);
			panelCreateModPenalty = new PanelCreateModPenalty(callDB, connection, fieldName); //Create a new CreateMod panel
		}

		panelCreateModPenalty.setName("panelCreateModPenalty"); //Set the name of the panel
		panelCreateModPenalty.getButtonBack().addActionListener(actionListener);
		
		addNewAndRemoveOldPanel(panelCreateModPenalty); //Change the current panel

		setCurrentPanelFlags(true); //Change the current panel flag to true
	}	
	
	public void showPanelLaunchExamination() throws CheckDataException, FormatScrollPaneException, ComboModelException, LoadDriverException
	{
		setCurrentPanelFlags(false); //Change the current panel flag to false
		
		//Table Penalty
		String[] tabHeader = {"Time", "Percentage"}; //Create the headers of the columns
		GeneralMethod.clearAndSetHeader(tabHeader, "left"); //Fill the arrayList by the tabHeader
		
		GeneralInformation.createPenaltyDescriptModel(connection, 1);
		GeneralMethod.setLeftModel(GeneralInformation.getPenaltyDescriptModel()); //Set the Generic Left JTable by the MyTableModel
		
		//Table Examination
		String[] tabDescriptHeader = {"Matricul", "Firstname", "Lastname"}; //Create the headers of the columns
		GeneralMethod.clearAndSetHeader(tabDescriptHeader, "descript"); //Fill the arrayList by the tabHeader
		
		GeneralInformation.createExamModel(connection);			
		int id = (int)GeneralInformation.getExamModel().getValueAt(0, 2);

		GeneralInformation.createStudentListModel(connection, id);
		GeneralMethod.setDescriptModel(GeneralInformation.getStudentListModel());
		
		//Creation of the panel
		panelLaunchExamination = new PanelLaunchExamination(callDB, connection); //Create a new Launch panel
		panelLaunchExamination.setName("panelLaunchExamination"); //Set the name of the panel
		
		//Add Listener
		MyActionListener actionListener = new MyActionListener();
		panelLaunchExamination.getButtonReady().addActionListener(actionListener);
		
		addNewAndRemoveOldPanel(panelLaunchExamination); //Change the current panel
					
		setCurrentPanelFlags(true); //Change the current panel flag to true
	}
	
	public void showPanelAbout(String titleLabel)
	{
		setCurrentPanelFlags(false);
		
		this.titleLabel = titleLabel; //Set the title of the panel
		
		panelAbout = new PanelAbout(this.titleLabel); //Create a new About panel
		panelAbout.setName("panelAbout"); //Set the name of the panel
		
		addNewAndRemoveOldPanel(panelAbout); //Change the current panel
		
		setCurrentPanelFlags(true); //Change the current panel flag to true
	}	

	private class MyActionListener implements ActionListener
	{
		public void actionPerformed(ActionEvent arg0)
		{
			try
			{
				if(arg0.getSource() == itemExit)
					System.exit(0);
				else if(arg0.getSource() == itemSwitch)
				{
					dispose();
					new WindowManager();
				}
				else if(arg0.getSource() == itemAssessement)
					showPanelAssessment();
				else if(arg0.getSource() == itemExamination)
					showPanelExamination();
				else if(arg0.getSource() == itemCourse)
					showPanelCourse();
				else if(arg0.getSource() == itemLaunch)
					showPanelLaunchExamination();
				else if(arg0.getSource() == itemPenalty)
					showPanelPenalty();
				else if(arg0.getSource() == itemFAQ)
					showPanelAbout("F.A.Q");
				else if(arg0.getSource() == itemContact)
					showPanelAbout("Logs");
				else if(arg0.getSource() == itemHelp)
					showPanelAbout("Help");
				else if(panelCourseFlag == true)
					{
						if(arg0.getSource() == panelCourse.getButtonCreate()) //If the source is Create
							showCreateModCourse("Create"); //Show the create assessment panel
						else if(arg0.getSource() == panelCourse.getButtonModify()) //If the source is Modify
							showCreateModCourse("Modify"); //Show the modify assessment panel
						//else{} //for other case to prevent evolution
					}
				else if(panelCreateModCourseFlag == true)
					{
						if(arg0.getSource() == panelCreateModCourse.getButtonBack())
							showPanelCourse();
					}
				else if(panelAssessmentFlag == true)
					{
						//Only if there is a subPanel, in the other case, DONT USE IT;
					}
				else if(panelExaminationFlag == true) //If the examination panel exists
					{
						if(arg0.getSource() == panelExamination.getButtonCreate())	
							showCreateModExamination("Create");
						else if(arg0.getSource() == panelExamination.getButtonModify())
						{
							int selectedRow = panelExamination.getTableLeft().convertRowIndexToModel(panelExamination.getTableLeft().getSelectedRow()); //Get the index of the selected row
							boolean result = new ExaminationMgmt(connection).miniCheckModifyElement(Integer.parseInt(GeneralInformation.getExamModel().getValueAt(selectedRow, 2).toString()));
							
							if(result == true) //If the modification is permitted
								showCreateModExamination("Modify");
							else
								TreatError.showError(new ModificationDBException());
						}
					}
				else if(panelCreateModExaminationFlag == true)
					{
						if(arg0.getSource() == panelCreateModExamination.getButtonBack())
							showPanelExamination();
					}
				else if(panelPenaltyFlag == true) //If the assessment panel exists
					{
						if(arg0.getSource() == panelPenalty.getButtonCreate()) //If the source is Create
							showCreateModPenalty("Create"); //Show the create assessment panel
						else if(arg0.getSource() == panelPenalty.getButtonModify()) //If the source is Modify
							{
								int selectedRow = panelPenalty.getTableLeft().convertRowIndexToModel(panelPenalty.getTableLeft().getSelectedRow()); //Get the index of the selected row
								boolean result = new PenaltyMgmt(connection).miniCheckModifyElement(Integer.parseInt(GeneralInformation.getPenaltyModel().getValueAt(selectedRow, 2).toString()));
								
								if(result == true) //If the modification is permitted
									showCreateModPenalty("Modify");
								else
									TreatError.showError(new ModificationDBException());
							}
					}
				else if(panelCreateModPenaltyFlag == true)
					{
						if(arg0.getSource() == panelCreateModPenalty.getButtonBack())
						{
							new PenaltyMgmt(connection).cleanPenaltyTemp();
							showPanelPenalty();
						}
					}
				else if(panelLaunchExaminationFlag == true) //If the launch panel exists
					{
						if(arg0.getSource() == panelLaunchExamination.getButtonReady()) //If the source is the button Start
						{
							PenaltyMgmt penaltyMgmt = new PenaltyMgmt(connection);
							int time = penaltyMgmt.selectTimeMax(panelLaunchExamination.getIdPenaltyForLaunch());
							
							AssessmentMgmt assessMgmt = new AssessmentMgmt(connection);
							assessMgmt.prepareAllAssessments(panelLaunchExamination.getIdExamForLaunch(), panelLaunchExamination.getIdPenaltyForLaunch());
							
							int nbRow = panelLaunchExamination.getTableDescript().getRowCount(); //Getting of the selected rows
						
							for(cptTab = 0; cptTab < nbRow; cptTab++) //While this is not the end of what we selected
							{
								student = new Student(connection, time, (int)(panelLaunchExamination.getTableDescript().getModel().getValueAt(cptTab, 0))); //Creation of the a Student object
								arrayStudent.add(student); //Moving it into the arrayList
							}
							
							projoScreen = new ProjoScreen(arrayStudent); //Load the projector screen
							setVisible(false); //Dispose this window
						}
					}
					else
						System.out.println("nothing selected"); //To avoid null pointer Exception
			}
			catch(NumberFormatException | CheckDataException | InsertionDataException | LoadDriverException | ComboModelException | FormatScrollPaneException | OperationImpossibleException | OpenConnectionException | EraseDataException error)
			{
				TreatError.showError(error);
			}
			
			container.validate(); //Refresh the screen
		}
	}
	
	public void addMenuBar(MyActionListener actionListener) //Add the menu bar with item
	{
		menuBar = new JMenuBar();
		setJMenuBar(menuBar);
				
		menuHome = new JMenu("Home");
		menuBar.add(menuHome);
		
		itemSwitch = new JMenuItem("Switch zone");
		menuHome.add(itemSwitch);
		
		itemExit = new JMenuItem("Exit");
		menuHome.add(itemExit);
		
		///////////////////////////////////////////////
		
		menuReport = new JMenu("Report");
		menuBar.add(menuReport);
		
		itemAssessement = new JMenuItem("Assessment");
		menuReport.add(itemAssessement);
		
		///////////////////////////////////////////////
		
		menuManagement = new JMenu("Management");
		menuBar.add(menuManagement);
		
		itemExamination = new JMenuItem("Examination");
		menuManagement.add(itemExamination);
		
		itemCourse = new JMenuItem("Course");
		menuManagement.add(itemCourse);
		
		itemPenalty = new JMenuItem("Penalty");
		menuManagement.add(itemPenalty);
		
		itemLaunch = new JMenuItem("Launch");
		menuManagement.add(itemLaunch);
		
		///////////////////////////////////////////////
	
		menuAbout = new JMenu("Help");
		menuBar.add(menuAbout);
		
		itemFAQ = new JMenuItem("F.A.Q");
		menuAbout.add(itemFAQ);
		
		itemContact = new JMenuItem("Contact");
		menuAbout.add(itemContact);
		
		itemHelp = new JMenuItem("Help");
		menuAbout.add(itemHelp);
	}
	
	public void addItemMenuListener(ActionListener actionListener) //Link the listener to all item
	{
		//itemHome.addActionListener(actionListener);
		itemSwitch.addActionListener(actionListener);
		itemExit.addActionListener(actionListener);
		itemAssessement.addActionListener(actionListener);
		itemExamination.addActionListener(actionListener);
		itemCourse.addActionListener(actionListener);
		itemPenalty.addActionListener(actionListener);
		itemLaunch.addActionListener(actionListener);
		itemFAQ.addActionListener(actionListener);
		itemContact.addActionListener(actionListener);
		itemHelp.addActionListener(actionListener);
	}
	
	public void setSwitchZone()
	{
		if(GeneralMethod.getSession().getManager() == false)
			itemSwitch.setEnabled(false);
	}
	
	public void addNewAndRemoveOldPanel(JPanel currentPanel) //Remove the currentPanel and set a new currentPanel
	{
		container.remove(this.currentPanel);
		this.currentPanel = currentPanel;
		container.add(this.currentPanel);
	}
	
	public void setCurrentPanelFlags(boolean state) //Set the current panel flag to true
	{
		if(this.currentPanel.getName().equals("panelAssessment") == true)
			panelAssessmentFlag = state;
		else if(this.currentPanel.getName().equals("panelExamination") == true)
			panelExaminationFlag = state;
		else if(this.currentPanel.getName().equals("panelCreateModExamination") == true)
			panelCreateModExaminationFlag = state;
		else if(this.currentPanel.getName().equals("panelCourse") == true)
			panelCourseFlag = state;
		else if(this.currentPanel.getName().equals("panelCreateModCourse") == true)
			panelCreateModCourseFlag = state;
		else if(this.currentPanel.getName().equals("panelPenalty") == true)
			panelPenaltyFlag = state;
		else if(this.currentPanel.getName().equals("panelCreateModPenalty") == true)
			panelCreateModPenaltyFlag = state;
		else if(this.currentPanel.getName().equals("panelLaunchExamination") == true)
			panelLaunchExaminationFlag = state;
		else if(this.currentPanel.getName().equals("panelCourse") == true)
			panelCourseFlag = state;
		else if(this.currentPanel.getName().equals("panelAbout") == true) {
		}
	}
	
	private class MyWindowListener extends WindowAdapter{ //If user close the main window -> EXIT
		public void windowClosing(WindowEvent arg0){
			try
			{
				new PenaltyMgmt(connection).cleanPenaltyTemp();
			}
			catch(EraseDataException | LoadDriverException error)
			{
				TreatError.showError(error);
			}
			System.exit(0);}}
}